package ru.bytedog.oiot.counter.bot.util;

import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class FormatterUtils {

    private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("dd.MM HH:mm");
    private static final DateTimeFormatter TIME_FORMATTER = DateTimeFormatter.ofPattern("HH:mm");

    private FormatterUtils() {
    }

    public static String formatDateTime(LocalDateTime time) {
        return formatDate(time, DATE_TIME_FORMATTER);
    }

    public static String formatTime(LocalDateTime time) {
        return formatDate(time, TIME_FORMATTER);
    }

    private static String formatDate(LocalDateTime time, DateTimeFormatter formatter) {
        if (time == null) {
            return StringUtils.EMPTY;
        }
        return formatter.format(time);
    }
}
